package com.company.permission.dao;

import com.company.permission.entity.Role;
import com.company.permission.mapper.RoleMapper;
import com.company.permission.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class RoleDao {

    /**
     * 任务二：查询特定角色及其所拥有的所有菜单权限
     */
    public Role findRoleWithMenusById(Long roleId) {
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()) {
            RoleMapper mapper = sqlSession.getMapper(RoleMapper.class);
            return mapper.findRoleWithMenusById(roleId);
        }
    }

    public Role findRoleWithMenusByRoleKey(String roleKey) {
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()) {
            RoleMapper mapper = sqlSession.getMapper(RoleMapper.class);
            return mapper.findRoleWithMenusByRoleKey(roleKey);
        }
    }
}